package com.mida.app.report.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.mida.app.report.service.MasterDataSvc;
import com.mida.dms.mdm.api.provider.*;
import com.mida.dms.mdm.dto.ServiceInstance;
import com.mida.dms.mdm.pojo.auto.MsdDataSet;
import com.mida.dms.mdm.pojo.auto.MsdServiceInstance;
import com.mida.dms.mdm.vo.PullDownMenuVO;
import com.mida.dms.mdm.vo.provider.BaseOrgInfoVo;
import com.mida.dms.mdm.vo.provider.BusinessUnitVo;
import com.mida.dms.mdm.vo.provider.EmployeeInfoVo;
import com.mida.dms.mdm.vo.provider.ServiceInstancePageVo;
import com.mida.tool.common.result.ListResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * 主数据Api实现
 *
 * @author Peng.Wu
 * @version version-1.0
 * @date 2021/6/22 19:06
 */
@Service
public class MasterDataSvcImpl implements MasterDataSvc {

    private ILocationApi iLocationApi;

    private IDetailCodingSystemApi iDetailCodingSystemApi;

    private IServiceInstanceApi iServiceInstanceApi;

    private IEmployeeInfoApi iEmployeeInfoApi;

    private IBusinessUnitApi iBusinessUnitApi;

    private IDeviceInfoApi iDeviceInfoApi;

    private IOrgInfoApi iOrgInfoApi;

    private IDataSetApi iDataSetApi;

    //private OIDGaneratorApi oidGaneratorApi;

    private IServiceLocationApi iServiceLocationApi;

    private ICodingRuleInfoApi iCodingRuleInfoApi;

    @Autowired
    public MasterDataSvcImpl(ILocationApi iLocationApi, IDetailCodingSystemApi iDetailCodingSystemApi,
                             IServiceInstanceApi iServiceInstanceApi, IEmployeeInfoApi iEmployeeInfoApi,
                             IBusinessUnitApi iBusinessUnitApi, IDeviceInfoApi iDeviceInfoApi, IDataSetApi iDataSetApi,
                             IOrgInfoApi iOrgInfoApi, IServiceLocationApi iServiceLocationApi,
                             ICodingRuleInfoApi iCodingRuleInfoApi) {
        this.iLocationApi = iLocationApi;
        this.iDetailCodingSystemApi = iDetailCodingSystemApi;
        this.iServiceInstanceApi = iServiceInstanceApi;
        this.iEmployeeInfoApi = iEmployeeInfoApi;
        this.iBusinessUnitApi = iBusinessUnitApi;
        this.iDeviceInfoApi = iDeviceInfoApi;
        this.iDataSetApi = iDataSetApi;
        this.iOrgInfoApi = iOrgInfoApi;
        // this.oidGaneratorApi = oidGaneratorApi;
        this.iServiceLocationApi = iServiceLocationApi;
        this.iCodingRuleInfoApi = iCodingRuleInfoApi;
    }
//
//    @Override
//    public Set<ManualRegistrationDto> selectBusinessUnit() {
//        ListResult<List<BusinessUnitVo>> listUnderHospital = this.findBusinessUnitListUnderHospital(
//                null, RegisterRequestConst.CLINICAL_BUSINESS_UNIT, null);
//        if (!ObjectUtils.isEmpty(listUnderHospital) && !CollectionUtils.isEmpty(listUnderHospital.getData())) {
//            List<BusinessUnitVo> hospitalData = listUnderHospital.getData();
//            return hospitalData.stream().map(a -> {
//                ManualRegistrationDto businessUnitVo = new ManualRegistrationDto();
//                if (StringUtils.isNotBlank(a.getBusinessUnitName()) && !ObjectUtils.isEmpty(a.getBusinessUnitSoid())) {
//                    businessUnitVo.setBusinessUnitName(a.getBusinessUnitName());
//                    businessUnitVo.setBusinessUnitSoid(a.getBusinessUnitSoid());
//                }
//                return businessUnitVo;
//            }).collect(Collectors.toSet());
//        }
//        return null;
//    }

//    @Override
//    public List<ManualRegistrationDto> selectBillingDoctor(String businessUnitSoid) {
//
//        ListResult<List<EmployeeInfoVo>> listByBusinessUnitSoid =
//                iEmployeeInfoApi.findListByBusinessUnitSoid(Long.parseLong(businessUnitSoid), null);
//        if (!ObjectUtils.isEmpty(listByBusinessUnitSoid)) {
//            List<EmployeeInfoVo> employeeInfoVos = listByBusinessUnitSoid.getData();
//            return employeeInfoVos.stream().map(a -> {
//                ManualRegistrationDto businessUnitVo = new ManualRegistrationDto();
//                businessUnitVo.setEmployeeName(a.getEmployeeName());
//                businessUnitVo.setEmployeeSoid(a.getEmployeeSoid().toString());
//                return businessUnitVo;
//            }).collect(Collectors.toList());
//        }
//        return null;
//    }

    /**
     * 根据医院soid和业务单元类型soid搜索业务单元
     *
     * @param hospitalSoId 医院soid
     * @param buTypeCode   业务单元类型soid
     * @param search       检索条件:名称，代码，拼音码，五笔码
     * @return ListResult<List < BusinessUnitVo>>
     * @author peng.Wu
     * @date 14:11 2021/6/23
     */
    private ListResult<List<BusinessUnitVo>> findBusinessUnitListUnderHospital(Long hospitalSoId, Long buTypeCode,
                                                                               String search) {
        ListResult<List<BusinessUnitVo>> businessUnitListUnderHospital = iBusinessUnitApi.
                findBusinessUnitListUnderHospital(hospitalSoId, buTypeCode, search);
        return businessUnitListUnderHospital;
    }


//    @Override
//    public List<ManualRegistrationDto> selectExamUnit(BigDecimal businessUnitSoId, Long hospitalSoId, Long buTypeCode) {
//        boolean isExist = null != businessUnitSoId;
//        ListResult<List<BusinessUnitVo>> unitListUnderHospital = this.
//                findBusinessUnitListUnderHospital(hospitalSoId, buTypeCode, null);
//        if (!ObjectUtils.isEmpty(unitListUnderHospital) && !CollectionUtils.isEmpty(unitListUnderHospital.getData())) {
//            List<BusinessUnitVo> hospitalData = unitListUnderHospital.getData();
//            List<ManualRegistrationDto> businessUnitVos = hospitalData.stream().map(a -> {
//                ManualRegistrationDto businessUnitVo = new ManualRegistrationDto();
//                if (StringUtils.isNotBlank(a.getBusinessUnitName()) && !ObjectUtils.isEmpty(a.getBusinessUnitSoid())) {
//                    if(null != a.getBusinessUnitSoid()){
//                        businessUnitVo.setBusinessUnitSoid(a.getBusinessUnitSoid());
//                    }
//                    businessUnitVo.setExamUnitName(a.getBusinessUnitName());
//                    if(null != a.getBusinessUnitSoid()){
//                        businessUnitVo.setExamUnitSoid(a.getBusinessUnitSoid().toString());
//                    }
//                }
//                return businessUnitVo;
//            }).collect(Collectors.toList());
//            // 依据businessUnitSoId 过滤
//            if(isExist){
//                return businessUnitVos.stream()
//                        .filter(v -> null != v.getBusinessUnitSoid()
//                                && v.getBusinessUnitSoid().equals(businessUnitSoId.longValue()))
//                        .collect(Collectors.toList());
//            }
//            return businessUnitVos;
//        }
//        return null;
//    }

//    @Override
//    public DeviceInfoDto selectDeviceInfoByEquipmentRoomSoId(BigDecimal equipmentRoomSoId){
//        ListResult<com.mida.dms.mdm.dto.DeviceInfoDto> deviceInfoDtos =
//                iDeviceInfoApi.findOneByLocationSoid(equipmentRoomSoId.longValue());
//        if (!ObjectUtils.isEmpty(deviceInfoDtos) && null != deviceInfoDtos.getData().getDeviceSoid()) {
//            DeviceInfoDto deviceInfoVo = new DeviceInfoDto();
//            com.mida.dms.mdm.dto.DeviceInfoDto data = deviceInfoDtos.getData();
//            BeanUtils.copyProperties(data,deviceInfoVo);
//            if(!CollectionUtils.isEmpty(data.getExampleList())){
//                List<MsdMedicalDeviceExampleDto> collect = data.getExampleList().stream().map(v -> {
//                    MsdMedicalDeviceExampleDto vo = new MsdMedicalDeviceExampleDto();
//                    BeanUtils.copyProperties(v, vo);
//                    return vo;
//                }).collect(Collectors.toList());
//                deviceInfoVo.setExampleList(collect);
//            }
//            return deviceInfoVo;
//        }
//        return null;
//    }

//    @Override
//    public Page<MsdServiceInstancePageDto> selectMsdServiceInstance(String initials, Long examType,
//                                                                    Integer currentPage, Integer pageSize) {
//        ListResult<Page<ServiceInstancePageVo>> listByPage = iServiceInstanceApi.findListByPage(initials, currentPage
//                , pageSize, null, examType);
//        if (!ObjectUtils.isEmpty(listByPage)) {
//            MsdServiceInstancePageDto msdServiceInstancePageVo = new MsdServiceInstancePageDto();
//            List<MsdServiceInstanceDto> msdServiceInstanceVos = new ArrayList<>();
//            Page<ServiceInstancePageVo> data = listByPage.getData();
//            //总页数
//            msdServiceInstancePageVo.setPages(data.getPages());
//            //总记录数
//            msdServiceInstancePageVo.setTotal(data.getTotal());
//            List<ServiceInstancePageVo> records = data.getRecords();
//
//            for (ServiceInstancePageVo record : records) {
//                MsdServiceInstanceDto msdServiceInstanceVo = new MsdServiceInstanceDto();
//
//                List<SerivcePartSetDto> serivcePartSetVos = new ArrayList<>();
//
//                List<ExamMethodDto> examMethodVos = new ArrayList<>();
//
//                List<MsdServiceBusinessUnitSet> serviceBusinessUnitSetList = record.getServiceBusinessUnitSetList();
//                if (!CollectionUtils.isEmpty(serviceBusinessUnitSetList)) {
//                    List<BusinessDto> businessVos = new ArrayList<>();
//                    serviceBusinessUnitSetList.forEach(msdServiceBusinessUnitSet -> {
//                        BusinessDto businessVo = new BusinessDto();
//                        Long businessUnitSoid = msdServiceBusinessUnitSet.getBusinessUnitSoid();
//                        String dataSetName = this.getDataSetName(new BigDecimal(businessUnitSoid));
//                        businessVo.setBusinessUnitSoid(businessUnitSoid.toString());
//                        businessVo.setBusinessUnitSoidName(dataSetName);
//                        String strDefSoId = String.valueOf(msdServiceBusinessUnitSet.getServiceDefineSoid());
//                        businessVo.setBusinessDefSoId(strDefSoId);
//                        businessVos.add(businessVo);
//                    });
//                    msdServiceInstanceVo.setBusinessVoList(businessVos);
//                }
//                MsdServiceInstance serviceInstance = record.getServiceInstance();
//                if (!ObjectUtils.isEmpty(serviceInstance)) {
//                    //服务实例名称和soid
//                    msdServiceInstanceVo.setServiceInstanceName(serviceInstance.getServiceInstanceName());
//                    msdServiceInstanceVo.setMsdServiceInstanceSoid(serviceInstance.getMsdServiceInstanceSoid().toString());
//
//                    //检查服务类型
//                    Long examServiceType = serviceInstance.getExamServiceType();
//                    msdServiceInstanceVo.setExamServiceType(examServiceType.toString());
//                    String dataSetName = this.getDataSetName(new BigDecimal(examServiceType));
//                    msdServiceInstanceVo.setExamServiceTypeName(dataSetName);
//                    String strSoId = String.valueOf(serviceInstance.getServiceDefineSoid());
//                    msdServiceInstanceVo.setServiceDefSoId(strSoId);
//                }
//                List<ServiceInstancePartVo> serviceInstancePartVoList = record.getServiceInstancePartVoList();
//                for (ServiceInstancePartVo serviceInstancePartVo : serviceInstancePartVoList) {
//
//                    List<MsdServiceInstanceMethods> serivceInstanceMethods =
//                            serviceInstancePartVo.getSerivceInstanceMethods();
//                    //方法名称和soid
//                    for (MsdServiceInstanceMethods serivceInstanceMethod : serivceInstanceMethods) {
//                        Long examMethod = serivceInstanceMethod.getExamMethod();
//                        String dataSetName = this.getDataSetName(new BigDecimal(examMethod));
//                        ExamMethodDto examMethodVo = new ExamMethodDto();
//                        examMethodVo.setExamMethodName(dataSetName);
//                        examMethodVo.setExamMethod(examMethod.toString());
//                        examMethodVos.add(examMethodVo);
//                    }
//                    SerivcePartSetDto serivcePartSetVo = new SerivcePartSetDto();
//                    serivcePartSetVo.setExamMethodVoList(examMethodVos);
//                    //部位名称和soid
//                    MsdServicePartSet serivcePartSet = serviceInstancePartVo.getSerivcePartSet();
//                    if (!ObjectUtils.isEmpty(serivcePartSet)) {
//                        Long examParts = serivcePartSet.getExamParts();
//                        String dataSetName = this.getDataSetName(new BigDecimal(examParts));
//                        serivcePartSetVo.setSerivcePartSetName(dataSetName);
//                        serivcePartSetVo.setSerivcePartSetSoid(examParts.toString());
//                        String strDefSoId = String.valueOf(serivcePartSet.getServiceDefineSoid());
//                        serivcePartSetVo.setServicePartDefSoId(strDefSoId);
//                    }
//                    serivcePartSetVos.add(serivcePartSetVo);
//                }
//                msdServiceInstanceVo.setServicePartSetVoList(serivcePartSetVos);
//                msdServiceInstanceVos.add(msdServiceInstanceVo);
//            }
//            msdServiceInstancePageVo.setMsdServiceInstanceVoList(msdServiceInstanceVos);
//            List<MsdServiceInstancePageDto> msdServiceInstancePageVos = new ArrayList<>();
//            msdServiceInstancePageVos.add(msdServiceInstancePageVo);
//            Page<MsdServiceInstancePageDto> msdServiceInstancePageVoPage =
//                    new Page<>(currentPage, pageSize);
//            msdServiceInstancePageVoPage.setRecords(msdServiceInstancePageVos);
//            return msdServiceInstancePageVoPage;
//        }
//        return null;
//    }

//    @Override
//    public List<ManualRegistrationDto> selectVisitScence() {
//        List<PullDownMenuVO> drawer = this.drawer(RegisterRequestConst.VISIT_SCENCE_CODE);
//        if(CollectionUtils.isEmpty(drawer)){
//            return null;
//        }
//        List<ManualRegistrationDto> visitScenceVos = new ArrayList<>();
//        for (PullDownMenuVO pullDownMenuVO : drawer) {
//            ManualRegistrationDto visitScenceVo = new ManualRegistrationDto();
//            visitScenceVo.setVisitScenceName(pullDownMenuVO.getValue());
//            visitScenceVo.setVisitScenceCode(pullDownMenuVO.getCode());
//            visitScenceVos.add(visitScenceVo);
//        }
//        return visitScenceVos;
//    }

//    @Override
//    public List<ManualRegistrationDto> emergencyLevel() {
//        List<ManualRegistrationDto> strings = new ArrayList<>();
//        List<PullDownMenuVO> dhucvdt0110 = this.drawer(RegisterRequestConst.EMERGENCY_LEVEL);
//        if(null == dhucvdt0110){
//            return strings;
//        }
//        for (PullDownMenuVO pullDownMenuVO : dhucvdt0110) {
//            if (StringUtils.isNotBlank(pullDownMenuVO.getValue())) {
//                ManualRegistrationDto manualRegistrationVo = new ManualRegistrationDto();
//                String value = pullDownMenuVO.getValue();
//                String code = pullDownMenuVO.getCode();
//                manualRegistrationVo.setEmergencySign(code);
//                manualRegistrationVo.setEmergencySignName(value);
//                strings.add(manualRegistrationVo);
//            }
//        }
//        return strings;
//    }

//    @Override
//    public List<DiagnosisDto> queryDiagnosis() {
//        List<PullDownMenuVO> dhucv1034 = this.drawer(RegisterRequestConst.DIAGNOSIS_CODE);
//        List<DiagnosisDto> diagnosisVos = new ArrayList<>();
//        if (!CollectionUtils.isEmpty(dhucv1034)) {
//            for (PullDownMenuVO pullDownMenuVO : dhucv1034) {
//                DiagnosisDto diagnosisVo = new DiagnosisDto();
//                String value = pullDownMenuVO.getValue();
//                String code = pullDownMenuVO.getCode();
//                diagnosisVo.setDiagnosis(code);
//                diagnosisVo.setDiagnosisName(value);
//                diagnosisVos.add(diagnosisVo);
//            }
//        }
//        return diagnosisVos;
//    }

//    @Override
//    public List<CardCodingSystemDto> getCardInfoByCodeIdentifier(String codeIdentifier) {
//        List<CardCodingSystemDto> cards = new ArrayList<>();
//        List<PullDownMenuVO> dhucvdt0110 = this.drawer(codeIdentifier);
//        if(null == dhucvdt0110){
//            return cards;
//        }
//        for (PullDownMenuVO pullDownMenuVO : dhucvdt0110) {
//            if (StringUtils.isNotBlank(pullDownMenuVO.getValue())) {
//                CardCodingSystemDto cardCodingSystemVo = new CardCodingSystemDto();
//                String value = pullDownMenuVO.getValue();
//                String code = pullDownMenuVO.getCode();
//                cardCodingSystemVo.setCardTypeCode(code);
//                cardCodingSystemVo.setCardDesc(value);
//                cardCodingSystemVo.setCardUsageCode(codeIdentifier);
//                cards.add(cardCodingSystemVo);
//            }
//        }
//        return cards;
//    }

//    @Override
//    public List<ManualRegistrationDto> selectCheckType() {
//        List<ManualRegistrationDto> manualRegistrationVos = new ArrayList<>();
//        List<PullDownMenuVO> dhucvdt0021 = this.drawer(RegisterRequestConst.CHECK_SERVICE_TYPE);
//        if (!CollectionUtils.isEmpty(dhucvdt0021)) {
//            for (PullDownMenuVO pullDownMenuVO : dhucvdt0021) {
//                ManualRegistrationDto manualRegistrationVo = new ManualRegistrationDto();
//                manualRegistrationVo.setExamType(pullDownMenuVO.getValue());
//                manualRegistrationVo.setExamTypeCode(pullDownMenuVO.getCode());
//                manualRegistrationVos.add(manualRegistrationVo);
//            }
//            return manualRegistrationVos;
//        }
//        return null;
//    }


//    @Override
//    public String selectOrgLocationBySoid(String employeeSoid) {
//        ListResult<BaseOrgInfoVo> orgByOrgInfoSoid = iOrgInfoApi.findOrgByOrgInfoSoid(Long.parseLong(employeeSoid),
//                false);
//        BaseOrgInfoVo data = orgByOrgInfoSoid.getData();
//        return data.getOrgInfoName();
//    }

    @Override
    public List<PullDownMenuVO> drawer(String businessUnitCode) {
        ListResult<List<PullDownMenuVO>> drawer =
                iDetailCodingSystemApi.drawer(businessUnitCode, null, false, null);
        if (CollectionUtils.isEmpty(drawer.getData())) {
            return null;
        }
        return drawer.getData();
    }

    /**
     * 通过SoId 获取字段名
     *
     * @param soid SoId
     * @return 字段名
     * @author peng.Wu
     * @date 10:05 2021/6/23
     */
    @Override
    public String getDataSetName(BigDecimal soid) {
        String name = "";
        if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(soid)) {
            ListResult<MsdDataSet> conceptSoidByDataSetSoid =
                    iDataSetApi.getConceptSoidByDataSetSoid(soid.longValueExact());
            if (ObjectUtil.isNotEmpty(conceptSoidByDataSetSoid.getData()) && ObjectUtil.isNotEmpty(conceptSoidByDataSetSoid.getData().getDataSetMeaning())) {
                name = conceptSoidByDataSetSoid.getData().getDataSetMeaning();
            }
        }
        return name;
    }

    /**
     * 从主数据获取检查服务实例信息
     *
     * @param msdServiceInstanceSoid 查服务实例SoId
     * @return ListResult<List < ServiceInstance>>
     * @author peng.Wu
     * @date 14:31 2021/6/23
     */
    @Override
    public ListResult<List<ServiceInstance>> findServiceInstanceInfoBySoid(BigDecimal msdServiceInstanceSoid) {
        return iServiceInstanceApi.findServiceInstanceInfoBySoid(msdServiceInstanceSoid.longValueExact());
    }

    /**
     * 获取机房地址
     *
     * @param equipmentRoomSoid 机房SoId
     * @return 机房地址
     * @author peng.Wu
     * @date 17:19 2021/6/23
     */
    @Override
    public String getEngineRoomAddress(BigDecimal equipmentRoomSoid) {
        if (!ObjectUtils.isEmpty(equipmentRoomSoid)) {
            //根据equipmentRoomSoid查setAddrDetail
            ListResult<String> engineRoomLocationBySoid =
                    iLocationApi.findEngineRoomLocationBySoid(equipmentRoomSoid.longValue());
            if (!ObjectUtils.isEmpty(engineRoomLocationBySoid) && !ObjectUtils.isEmpty(engineRoomLocationBySoid.getData())) {
                return engineRoomLocationBySoid.getData();
            }
        }
        return "";
    }

    /**
     * 根据医生表述获取医院名称+院区
     *
     * @param requestDoctor 医生
     * @return java.lang.String
     * @author wangconghao
     * @date 2021/6/10 11:37
     */
    @Override
    public String getLocaltionNameByRequestDoctor(BigDecimal requestDoctor) {
        ListResult<List<BaseOrgInfoVo>> hospitalByEmployeeSoid =
                iOrgInfoApi.findHospitalByEmployeeSoid(requestDoctor.longValue());
        if (hospitalByEmployeeSoid != null) {
            List<BaseOrgInfoVo> baseOrgInfoVo = hospitalByEmployeeSoid.getData();
            if (baseOrgInfoVo != null) {
                String orgInfoName = baseOrgInfoVo.get(0).getOrgInfoName();
                if (StringUtils.isNotBlank(orgInfoName)) {
                    return orgInfoName;
                }
            }
        }
        return "";
    }

//    @Override
//    public BigDecimal getRandomEquipmentRoomByExamType(BigDecimal examType) {
//        Random rand = new Random();
//        try {
//            List<MsdServiceLocation> msdServiceLocations = iServiceLocationApi.findByExamServiceType(examType.longValue()).getData();
//            if (msdServiceLocations != null && msdServiceLocations.size() > 0) {
//                if (msdServiceLocations.size() == 0) {
//                    return new BigDecimal(msdServiceLocations.get(0).getLocationSoid());
//                } else {
//                    int i = rand.nextInt(msdServiceLocations.size());
//                    return new BigDecimal(msdServiceLocations.get(i).getLocationSoid());
//                }
//            } else {
//                return null;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }

    @Override
    public ListResult<String> getSerialNumberBySoid(Long codingRuleInfoSoid, Long orgInfoSoid, Long resourceInfoSoid,
                                                    Long userInfoSoid) {
        return iCodingRuleInfoApi.getSerialNumberBySoid(codingRuleInfoSoid, orgInfoSoid, resourceInfoSoid, userInfoSoid);
    }

    @Override
    public ListResult<EmployeeInfoVo> findOneBySoid(Long employeeSoid, boolean isIncludeDelete) {

        return iEmployeeInfoApi.findOneBySoid(employeeSoid, isIncludeDelete);
    }

    @Override
    public ListResult<BusinessUnitVo> findBusinessUnitBySoid(Long businessUnitSoid, boolean isIncludeDelete) {
        return iBusinessUnitApi.findBusinessUnitBySoid(businessUnitSoid, isIncludeDelete);
    }

    /**
     * 批量查询检查服务实例名称
     */
    @Override
    public Map<BigDecimal, String> findServiceInstanceInfosBySoids(List<BigDecimal> msdServiceInstanceSoids) {
        List<Long> parms = msdServiceInstanceSoids.stream().map(BigDecimal::longValueExact).collect(Collectors.toList());
        ListResult<List<ServiceInstancePageVo>> listBySoids = iServiceInstanceApi.findListBySoids(parms);
        Map<BigDecimal, String> res = new ConcurrentHashMap<>();
        if (ObjectUtils.isEmpty(listBySoids) || ObjectUtils.isEmpty(listBySoids.getData())) {
            return res;
        } else {
            List<ServiceInstancePageVo> serviceInstancePageVos = listBySoids.getData();
            res = serviceInstancePageVos.stream().filter(ObjectUtil::isNotEmpty)
                    .map(ServiceInstancePageVo::getServiceInstance)
                    .filter(a -> ObjectUtil.isNotEmpty(a.getMsdServiceInstanceSoid()))
                    .filter(a -> ObjectUtil.isNotEmpty(a.getServiceInstanceName()))
                    .collect(Collectors.toMap(a -> new BigDecimal(a.getMsdServiceInstanceSoid()), MsdServiceInstance::getServiceInstanceName, (key1, key2) -> key2));
        }
        return res;
    }


    /**
     * 批量查询业务单元名称
     */
    @Override
    public Map<BigDecimal, String> findBusinessUnitBySoids(List<BigDecimal> msdServiceInstanceSoids) {
        List<Long> parms = msdServiceInstanceSoids.stream().map(BigDecimal::longValueExact).collect(Collectors.toList());
        ListResult<List<BusinessUnitVo>> listBySoids = iBusinessUnitApi.findListBySoids(parms);
        Map<BigDecimal, String> res = new ConcurrentHashMap<>();
        if (ObjectUtils.isEmpty(listBySoids) || ObjectUtils.isEmpty(listBySoids.getData())) {
            return res;
        } else {
            List<BusinessUnitVo> BusinessUnitVos = listBySoids.getData();
            res = BusinessUnitVos.stream().filter(ObjectUtil::isNotEmpty)
                    .filter(a -> ObjectUtil.isNotEmpty(a.getBusinessUnitCode()))
                    .filter(a -> ObjectUtil.isNotEmpty(a.getBusinessUnitName()))
                    .collect(Collectors.toMap(a -> new BigDecimal(a.getBusinessUnitSoid()), BusinessUnitVo::getBusinessUnitName, (key1, key2) -> key2));
        }
        return res;
    }

    /**
     * 批量查询soid对应中文名称
     */
    @Override
    public Map<BigDecimal, String> findDataSetNamesBySoids(ArrayList<BigDecimal> dataSetSoids) {
        List<Long> parms = dataSetSoids.stream().map(BigDecimal::longValueExact).collect(Collectors.toList());
        ListResult<List<MsdDataSet>> listBySoids = iDataSetApi.getConceptSoidsByDataSetSoids(parms);
        Map<BigDecimal, String> res = new ConcurrentHashMap<>();
        if (ObjectUtils.isEmpty(listBySoids) || ObjectUtils.isEmpty(listBySoids.getData())) {
            return res;
        } else {
            List<MsdDataSet> MsdDataSets = listBySoids.getData();
            res = MsdDataSets.stream().filter(ObjectUtil::isNotEmpty)
                    .filter(a -> ObjectUtil.isNotEmpty(a.getDataSetSoid()))
                    .filter(a -> ObjectUtil.isNotEmpty(a.getDataSetMeaning()))
                    .collect(Collectors.toMap(a -> new BigDecimal(a.getDataSetSoid()), MsdDataSet::getDataSetMeaning, (key1, key2) -> key2));
        }
        return res;
    }

    /**
     * 批量查询员工姓名
     */
    @Override
    public Map<BigDecimal, String> findRequestDoctorNameBySoids(ArrayList<BigDecimal> requestDoctorSoids) {
        List<Long> parms = requestDoctorSoids.stream().map(BigDecimal::longValueExact).collect(Collectors.toList());
        ListResult<List<EmployeeInfoVo>> listBySoids = iEmployeeInfoApi.findListBySoids(parms);
        Map<BigDecimal, String> res = new ConcurrentHashMap<>();
        if (ObjectUtils.isEmpty(listBySoids) || ObjectUtils.isEmpty(listBySoids.getData())) {
            return res;
        } else {
            List<EmployeeInfoVo> EmployeeInfoVos = listBySoids.getData();
            res = EmployeeInfoVos.stream().filter(ObjectUtil::isNotEmpty)
                    .filter(a -> ObjectUtil.isNotEmpty(a.getEmployeeSoid()))
                    .filter(a -> ObjectUtil.isNotEmpty(a.getEmployeeName()))
                    .collect(Collectors.toMap(a -> new BigDecimal(a.getEmployeeSoid()), EmployeeInfoVo::getEmployeeName, (key1, key2) -> key2));
        }
        return res;
    }
}